package qlsl.androiddesign.activity.baseactivity;

import org.greenrobot.eventbus.EventBus;

import butterknife.ButterKnife;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.view.View;
import android.widget.ImageView;

import qlsl.androiddesign.application.SoftwareApplication;
import qlsl.androiddesign.constant.UIConfig;
import qlsl.androiddesign.view.baseview.FunctionView;
/**
 * 分离FunctionView层业务逻辑的处理<br/>
 * Activity层主要做展示数据<br/>
 */
public abstract class SeparateFunctionBaseActivity extends BaseActivity {

    public Context mContext;

    // protected SoftwareApplication mApp;
    private FragmentConfig fragmentConfig;

    protected FunctionView functionView;

    protected final static class FragmentConfig extends UIConfig {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        functionView = getFunctionView();
        functionView.setContentView(getLayoutId());
        // mApp = SoftwareApplication.getInstance();

        ButterKnife.bind(this);
        mContext = this;
        this.initView();

        fragmentConfig = new FragmentConfig();
        initUIConfig(fragmentConfig);
        if (fragmentConfig.isApplyEventBus) {
            EventBus.getDefault().register(this);
        }

    }

    protected void initUIConfig(FragmentConfig fragmentConfig) {

    }

    @Override
    public void onDestroy() {
        super.onDestroy();

        ButterKnife.unbind(this);

        if (fragmentConfig.isApplyEventBus) {
            EventBus.getDefault().unregister(this);
        }
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
    }

    public abstract int getLayoutId();

    public abstract void initView();

    /**
     * 查找View
     *
     * @param id   控件的id
     * @param <VT> View类型
     * @return
     */
    public <VT extends View> VT getViewById(@IdRes int id) {
        return (VT) findViewById(id);
    }

}
